﻿using MediatR;
using PLC.Domain.Models;
using PLC.Domain.Service.IRepository;

namespace PLC.Domain.Events.Handlers;

public class SavePressureDataHandler:INotificationHandler<SavePressureDataModel>
{
    private readonly IPressureDataRepository _pressureDataRepository;

    public SavePressureDataHandler(IPressureDataRepository pressureDataRepository)
    {
        _pressureDataRepository = pressureDataRepository?? throw new ArgumentNullException(nameof(pressureDataRepository));
    }
    public async Task Handle(SavePressureDataModel notification, CancellationToken cancellationToken)
    {
        if (notification.PressureDatas.Count==0)
        {
            return;
        }

        await _pressureDataRepository.CreateAsync(notification.PressureDatas);
    }
}